package example.controller;

import example.utils.Jwts_JWTUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * TODO
 *
 * @author zgq
 * @date 2020/10/22 13:35
 */
@RestController
public class JwtsController {
    @Autowired
    private Jwts_JWTUtil zn_jwtUtil;

    @GetMapping("/createToken/{loginName}")
    public String createToken(@PathVariable("loginName") String loginName) {
        String token = zn_jwtUtil.doGenerateToken(new HashMap<String, Object>(), loginName);
        return token;
    }

    @PostMapping("/parseToken")
    public Claims parseToken(String token) {
        Claims claims = zn_jwtUtil.parseToken(token);
        return claims;
    }

    @PostMapping("/verifyToken")
    public Boolean verifyToken(String token, String loginName) {
        return zn_jwtUtil.verifyToken(token, loginName);
    }

    @PostMapping("/isTokenExpired")
    public Boolean isTokenExpired(String token) {
        return zn_jwtUtil.isTokenExpired(token);
    }
}
